/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.niedziela12.pai.ejb.room.managers;

import com.niedziela12.pai.ejb.dto.RoomDTO;
import com.niedziela12.pai.ejb.entities.Room;
import com.niedziela12.pai.ejb.room.facades.RoomFacadeLocal;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

/**
 *
 * @author Kamil
 */
@Stateless
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public class RoomManager implements RoomManagerLocal {

    @EJB
    private RoomFacadeLocal roomFacade;

    @Override
    public void addNewRoom(RoomDTO room) {
        roomFacade.create(room.toRoom());
    }

    @Override
    public void updateRoomInfo(RoomDTO room) {
        roomFacade.edit(room.toRoom());
    }

    @Override
    public void deleteRoom(RoomDTO room) {
        roomFacade.remove(room.toRoom());
    }

    @Override
    public List<RoomDTO> getRooms(int from, int to) {
        List<Room> rooms = roomFacade.findRange(new int[]{from,to});
        List<RoomDTO> rdto = new ArrayList<RoomDTO>();
        for(Room r : rooms)rdto.add(new RoomDTO(r));
        return rdto;
    }

    @Override
    public List<RoomDTO> getAllRooms() {
        List<Room> rooms = roomFacade.findAll();
        List<RoomDTO> rdto = new ArrayList<RoomDTO>();
        for(Room r : rooms)rdto.add(new RoomDTO(r));
        return rdto;
    }

    @Override
    public int getRoomsCount() {
        return roomFacade.count();
    }

    @Override
    public RoomDTO getRoom(Long id) {
        return new RoomDTO(roomFacade.find(id));
    }

    @Override
    public List<RoomDTO> getRoomsInHotel(Long id) {
        List<Room> rooms = roomFacade.getHotelRooms(id);
        List<RoomDTO> rdto = new ArrayList<RoomDTO>();
        for(Room r : rooms)rdto.add(new RoomDTO(r));
        return rdto;
    }
    
    
}
